﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using NLBS.Entity;
using System.Data;

namespace NLBS.Data
{
    public partial class NHibernateDataProvider : DbProvider
    {
        public override IList<Widget> GetWidget()
        {
            return CurrentSession.CreateCriteria(typeof(Widget)).List<Widget>();
        }

        public override int InsertWidget(Widget widget)
        {
            CurrentSession.Save(widget);
            int result = 1;
            return result;
        }

        public override int UpdateWidget(Widget widget)
        {
            CurrentSession.Update(widget);
            CurrentSession.Flush();
            return 1;
        }

        public override int DeleteWidget(int id)
        {
            CurrentSession.Delete(GetWidgetDetail(id));
            CurrentSession.Flush();
            return 1;
        }

        public override Widget GetWidgetDetail(int id)
        {
            return CurrentSession.Get<Widget>(id);
        }
    }
}
